package com.feng.leetcode;

/**
 * @author feng
 * @decrition 如果第六杯到了后，前三行并没有全满，则第三行中间满了并且溢出了，第四行中间被中有
 * @date 2022/11/2021:58
 */
public class L799 {
    public static double champagneTower(int poured, int query_row, int query_glass) {
        if (poured == 0) {
            return 0;
        }
        int allGlass = query_row + 1;
        double[][] glases = new double[query_row + 2][allGlass + 1];
        glases[0][0] = poured;
        for (int i = 0; i < glases.length - 1; i++) {
            int count = 0;
            for (int j = 0; j < i + 1; j++) {
                double all = glases[i][j] - 1;
                if (all < 0) {
                    count++;
                    continue;
                }
                glases[i][j] = 1;
                glases[i + 1][count] += (all / 2);
                glases[i + 1][count + 1] += (all / 2);
                count++;
            }
        }
        return glases[query_row][query_glass];
    }

    public static void main(String[] args) {
        double v = champagneTower(6, 2, 0);
        System.out.println(v);
    }
}
